package ${meta.basePackage}${meta.moduleName};

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import ${meta.basePackage}${meta.moduleName}.repository.${name}Repository;

/**
* @author admin
* @date ${meta.cratedDate}
*/
@RequiredArgsConstructor

@RestController
@RequestMapping("/${name?uncap_first}")
public class ${name}Controller {

    private final ${name}Repository repository;

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void create(@RequestBody ${name} ${name?uncap_first}){
        repository.save(${name?uncap_first});
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable ${meta.idType} id){
        repository.deleteById(id);
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void update(@PathVariable ${name} db, @RequestBody ${name} ${name?uncap_first}){
        BeanUtils.copy(${name?uncap_first},db)
        repository.save(db);
    }

    @GetMapping("/{id}")
    public Demo get(@PathVariable("id") ${name} ${name?uncap_first}){
        return ${name?uncap_first}
    }

    @GetMapping
    public Page<${name}> findAll(<#list queryCriteriaList as item >${getType(item.name)?split('.')?last} ${item.name}<#if queryCriteriaList?size \gt 0>, </#if></#list>Pageable pageable){
        return repository.findAll(<#if queryCriteriaList?size != 0>${name}Spce.toSpec(<#list queryCriteriaList as item >${item.name}<#if queryCriteriaList?size \gt item_index+1>, </#if></#list>), </#if>pageable);
    }

    @GetMapping("/list")
    public List<${name}> listAll(<#list queryCriteriaList as item >${getType(item.name)?split('.')?last} ${item.name}<#if queryCriteriaList?size \gt item_index+1>, </#if></#list>){
        return repository.findAll(<#if queryCriteriaList?size != 0>${name}Spce.toSpec(<#list queryCriteriaList as item >${item.name}<#if queryCriteriaList?size \gt item_index+1>, </#if></#list>)</#if>);
    }
}
